
#ifndef NETBASE_H
#define NETBASE_H

// sys
#include <stdint.h>
#include <memory>
// mine
#include "util.h"

struct event_base;

namespace net_base {
class Listener;
class Connector;

/*!
 * @brief
 *  create a bunch of threads runing evbase on every each one of them
 *  when a Listener or Connector is reuqired, find a evbase by round-robin
 *  assign it to the new Listener or Connector
 */
class NetBase {
 public:
  NetBase(void);
  ~NetBase(void);
  
  /*!
   * get threads running
   */
  void Run(uint8_t threads_num = 1);

  /*!
   * shutdown, close all threads
   */
  void Shutdown(void);

  /*!
   * create new listener on one evbase choosed by round-robin
   */
  std::unique_ptr<Listener> NewListener(void);

  /*!
   * create new connector on one evbase choosed by round-robin
   */
  std::unique_ptr<Connector> NewConnector(void);

 private:
  /*!
   * get next evbase by round-robin
   */
  event_base* NextEvBase(void);

  NONCOPYABLE(NetBase);
  IMPL_DECL;
};
} // namespace net_base

#endif // NETBASE_H

